import { defineStore } from 'pinia';
import {JSEncrypt} from "jsencrypt";
import user from "../views/System/user/index.vue";

export const userStore = defineStore({
  id: 'user',
  state: () => {
    return {
      token: '',
      userInfo: {},
      product: {
        tenant: 0,
        list: []
      },
    }
  },
  persist: {
      enabled: true,
      strategies: [
        {
          key: 'token',
          storage: localStorage
        },
        {
          key: 'userInfo',
          storage: localStorage
        }
      ]
  }
});

export const passwordEncryption = (param: any) => {
  // ��̨���Ĺ�Կ
  const publicKey = '-----BEGIN RSA PUBLIC KEY-----\n' +
      'MIGJAoGBALEAoVvf2rW4nksP4cm3ZWhyEnhFUUnIPrQmaWkpR6mZ7Mn9FSmWDLUl\n' +
      '/EHCk5MirbS3iL8rKsaJGZIWtiPALwZjNbR4ZIeXY+WlcxrXUnkzzzMyo4FIl7gp\n' +
      'um7wuFnuKxUusIvAi6IRSwDokPNNb5+nqeGlT5FUDORK1vgwZgxxAgMBAAE=\n' +
      '-----END RSA PUBLIC KEY-----'
  let encryptor = new JSEncrypt() // �½�JSEncrypt����
  encryptor.setPublicKey(publicKey) // ���ù�Կ
  let passwordEncryp = encryptor.encrypt(param.toString()) // ��������м���
  return passwordEncryp
};